All production instances of
HCL™ Accelerate must be installed on a Kubernetes platform. As a part of this migration, the instance of
MongoDB need to be re-installed in a Kubernetes-accessible location. To migrate your MongoDB
database, follow the steps below. After completion of these steps, follow the Kubernetes
installation procedure to complete the installation of
HCL™ Accelerate.
About this task
To migrate a Docker Compose MongoDB database to Kubernetes complete the following steps:
Procedure
-
Export the existing Docker Compose MongoDB database.
-
Navigate to MongoDB database container shell.
docker exec -it <mongo_db_service> bash
-
Export all data from the MongoDB database.
-
Exit the MongoDB database container shell.
-
Copy the dump folder out of the MongoDB database container.
docker cp <mongo_db_service>:/dump <destination>
Save the destination location of the MongoDB export to use in the final step.
-
Install MongoDB database in Kubernetes.
-
Install the MongoDB Helm chart with a root password of your choice.
helm install <mongo_pod_full_name> --set
mongodbRootPassword=<root_password> bitnamo/mongodb
-
Create a non-root MongoDB user
-
Navigate to MongoDB database's Kubernetes pod..
kubectl exec -it --namespace default <mongo pod full
name>/bin/bash
-
Open a MongoDB Shell session as the root user.
mongo admin -u root -p <root_password>
-
Create a non-root MongoDB user with the following roles and permissions:
db.createUser
({
user: "<new_username>",
pwd: "<new_password>",
roles: [{role: "readWriteAnyDatabase",
db: "admin"}, {role: "dbAdminAnyDatabase",
db: "admin"}, {role: "clusterAdmin",
db: "admin"
}]})
-
Exit the MongoDB Shell.
-
Restore the Docker Compose database dump to the new MongoDB pod.
-
Use
kubectl get pods
to get all pods. Identify the MongoDB
pod.
-
Copy database dump folder from the Docker Compose installation location into the
MongoDB pod.
kubectl cp <docker_compose_mongodb_dump_location_filename>
<mongo_pod_full_name>:/tmp/
-
Navigate to MongoDB pod shell.
kubectl exec -it --namespace default
<mongo_pod_full_name>/bin/bash
-
Change directory to dump directory.
-
List all MongoDB folder to verify the contents.
Note: Each folder is a database in MongoDB.
-
Restore all database except
ADMIN
mongorestore
--uri="mongodb://<new_username>:<new_password>@localhost:27017/?authSource=admin"
<db_name> -d <db_name>
Note: Delete the Docker Compose MongoDB export that was copied
into the Kubermetes MongoDB pod at your earliest convenience.
-
Exit MongoDB pod shell.
exit
The new MongoDB server is ready for use. For Kubernetes installation directions,
see this page.